//device.h

#ifndef CROSS_DEVICE_H_
#define CROSS_DEVICE_H_

#include "UDPDevice.h"
#include "hidapi.h"
#include "cross_serial_port.h"
#include "define.h"






class CrossDevice {
public:
	/**************************************************************
	 * Default constructor: create an instance of our serial interface
	 *   object.
	 * Parameters: None, though it could be convenient to have default
	 *   settings specified here as well as possibly a default port name.
	 * Returns: Nothing(it is a constructor)
	 */
	CrossDevice();
	/*
	 * Default deconstructor: delete an instance of out serial interface
	 */
	~CrossDevice();
	
	
	static CrossDeviceList* getDeviceList(void);
	/*
	 * open: opens the serial port using port-name provided.
	 * Parameters:
	 *   portName: an array of chars containing a NULL terminated string
	 *     that is the port name that we want to open.
	 *     eg. COM1, COM2, COM4
	 * Returns: a boolean indicating success or failure
	 */
	bool open(char* deviceName);
	/*
	 * close: closes the serial port
	 * Parameters: None.
	 * Returns: a boolean indicating success or failure
	 */
	bool close();
	
	void setSpeed(int speed);

	/*
	*   parity: parity to be used. One of
	 *     'n' = None
	 *     'e' = Even
	 *     'o' = Odd
	*/
	void setParity(char parity);  
	/*
	 * readBuf: read in a buffer of words
	 * Parameters:
	 *   buf: The buffer to read words into
	 *   bufSize: the number of words to read. This should be less than
	 *     or equal to the size of buf
	 * Returns: the number of words actually read
	 */
	int readBuf(char * buf, int bufSize);
	/*
	 * writeBuf: write out a buffer of words
	 * Parameters:
	 *   buf: The buffer to write words from
	 *   bufSize: the number of words to write. This should be less than
	 *     or equal to the size of buf
	 * Returns: the number of words actually written
	 */
	int writeBuf(char * buf, int bufSize);
	
	sockaddr_in * getRemoteAddr(void);
	char *getRemoteIP(void);

private:
	hid_device *_crossDevice;
	CrossPlatformSerial *_serialDevice;
	UDPDevice *_udpDevice;
	int _speed;
	char _parity;
};























#endif